<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>


<div class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-warning" onclick = "setStatus(1)">通过</button>
        <button type="button" class="btn btn-warning" onclick = "setStatus(2)">拒绝</button>
        <button type="button" class="btn btn-warning" onclick = "setHot(1)">热门</button>
        <button type="button" class="btn btn-warning" onclick = "setHot(0)">非热门</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

<table class = "table">
	<tr>
		<th>id</th>
		<th>图</th>
		<td>标题</td>
		<td>发布时间</td>
		<td>状态</td>
		<td>热门</td>
		<td>栏目</td>
		<td>分类</td>
		<td>作者</td>
		
	</tr>
	<!--   id, title, content, picture, channel_id, category_id, user_id, hits,
				   hot, status, deleted, created, updated, commentCnt, articleType -->
	<c:forEach items="${articlePage.list }" var="article">
		<tr>
			<td>${article.id }</td>
			<td><img alt="" width = "80" height = "60px" src="/pic/${article.picture }" onerror=""></td>
			<td>
			
			<a href="javascript:showDetail(${article.id})">${article.title }</a>
			
			</td>
			<td>
				<fmt:formatDate value="${article.created }" pattern="yyyy-MM-dd"/>
			</td>
			<td>
				<c:if test="${article.status == 0 }">待审核</c:if>
				<c:if test="${article.status == 1 }">通过</c:if>
				<c:if test="${article.status == 2 }">未通过</c:if>
			</td>
			<td>${article.hot == 1?'热门':'非热门' }</td>
			<td>${article.channel.name }</td>
			<td>${article.category.name }</td>
			<td>${article.author.username }</td>
		</tr>
	</c:forEach>

	

</table>

			<!--分页  -->
					<nav aria-label="Page navigation example">
					  <ul class="pagination">
					    <li class="page-item">
					      <a class="page-link" href="javascript:void(0)"  onclick="gotoPage(1)">
					        <span aria-hidden="true">&laquo;</span>
					      </a>
					    </li>
					    <c:forEach begin="${articlePage.pageNum-2>1?articlePage.pageNum-2:1 }"
					    	 end="${articlePage.pageNum+2<articlePage.pages?articlePage.pageNum+2:articlePage.pages }" step="1" var = "page">
					   	 	<li class="page-item"><a class="page-link" href="javascript:void(0)"    onclick="gotoPage(${page })" >${page }</a></li>
					   </c:forEach>
					    <li class="page-item">
					      <a class="page-link" href="javascript:void(0)" aria-label="Next"  onclick="gotoPage(${articlePage.pages})">
					        <span aria-hidden="true">&raquo;</span>
					      </a>
					    </li>
					  </ul>
					</nav>				                                                                                                                  
				<!--分页  -->

	<script type="text/javascript">
		
		var global_id = 0;
	
		function gotoPage(page){
			
			$("#workContent").load("/admin/showArticle?pageNum="+page);
		}
	
		function showDetail(articleId){
			
			global_id = articleId;
			
			$.get("/admin/getArticle",{id:articleId},function(msg){
				
				if(msg.id == 0){
					$(".modal-body").html(msg.t.content);
					$(".modal-title").html(msg.t.title);
					$(".modal").modal("show");
				}
				
				
			},"json")
		}
	
		function setStatus(statusId){
			$.get("/admin/setStatus",{id:global_id,statusId:statusId},function(msg){
				$(".modal").modal("hide");
				global_id = 0;
			},"json");	
		}
		
		function setHot(){
			$.get("/admin/setHot",{id:global_id,statusId:statusId},function(msg){
				$(".modal").modal("hide");
				global_id = 0;
			},"json");	
		}
		// 	这是干啥的？
		$('#articcleModal').on('hidden.bs.modal', function (e) {
			$("#workContent").load("/admin/showArticle?page=${articlePage.pageNum}");
		})
		
	</script>

